var SoDaoNotify = {
    _timerArr: null,
    init: function () {
        window.setTimeout("SoDaoNotify.refresh()", 1000);
        SoDaoNotify._timerArr = newMessageRemind.show();
    },
    refresh: function () {
        if (!document.getElementById("divNoticeTip"))
            return;
        var ajax = {
            url: "/message/GetUserNotice", type: "get", dataType: "json", cache: false,
            success: function (data) {
                SoDaoNotify.InnerNotice(data);
                window.setTimeout("SoDaoNotify.refresh()", 40000);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) { window.setTimeout("SoDaoNotify.refresh()", 40000); }
        };
        $.ajax(ajax);
    },
    init_space: function () {
        window.setTimeout("SoDaoNotify.refresh_space()", 1000);
        SoDaoNotify._timerArr = newMessageRemind.show();
    },
    refresh_space: function () {
        if (!document.getElementById("divNoticeTip"))
            return;
        var ajax = {
            url: "/message/GetUserNotice", type: "get", dataType: "json", cache: false,
            success: function (data) {
                SoDaoNotify.InnerNotice(data);
                window.setTimeout("SoDaoNotify.refresh_space()", 40000);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) { window.setTimeout("SoDaoNotify.refresh_space()", 40000); }
        };
        $.ajax(ajax);
    },
    InnerNotice: function (data) {
        if (data != null && data != "" && data.json != null && data.json != "") {
            var showTip = 0;
            var float_p = "";
            var json = eval(data.json);
            if (json.length <= 0) {
                $("#divNoticeTip").hide();
                newMessageRemind.delTip();
                return;
            }
            for (var i = 0; i < json.length; i++) {
                if (json[i].count > 0 && json[i].typeId > 0) {
                    var p;
                    switch (json[i].typeId) {
                        case 1:
                            p = "<p id='WB_unread_msg_1'>" + json[i].count + "位新粉丝，<a href='http://www.sodao.com/home/friend/fans' target='_blank'>查看我的粉丝</a></p>";
                            break;
                        case 2:
                            p = "<p id='WB_unread_msg_2'>" + json[i].count + "位新好友，<a href='http://www.sodao.com/home/friend/list' target='_blank'>查看我的好友</a></p>";
                            break;
                        case 3:
                            p = "<p id='WB_unread_msg_3'>" + json[i].count + "条新评论，<a href='http://www.sodao.com/home/dynamic/commentmsglist' target='_blank'>查看评论</a></p>";
                            break;
                        case 4:
                            p = "<p id='WB_unread_msg_4'>" + json[i].count + "条新留言，<a href='http://i.sodao.com/" + data.user + "/guestbook.html' target='_blank'>查看留言</a></p>";
                            break;
                        case 5:
                            p = "<p id='WB_unread_msg_5'>" + json[i].count + "条新回复，<a href='http://www.sodao.com/home/message/notice' target='_blank'>查看回复</a></p>";
                            break;
                        case 6:
                            p = "<p id='WB_unread_msg_6'>" + json[i].count + "条新转载，<a href='http://www.sodao.com/home/message/notice' target='_blank'>查看转载</a></p>";
                            break;
                        case 7:
                            p = "<p id='WB_unread_msg_7'>" + json[i].count + "条新分享，<a href='http://www.sodao.com/home/message/notice' target='_blank'>查看分享</a></p>";
                            break;
                        case 8:
                            p = "<p id='WB_unread_msg_9'>" + json[i].count + "份新礼物，<a href='http://www.sodao.com/home/gift/MyReceive' target='_blank'>查看礼物</a></p>";
                            break;
                        case 9:
                            p = "<p id='WB_unread_msg_9'>" + json[i].count + "条新请求，<a href='http://www.sodao.com/home/message/demand#rt=1' target='_blank'>查看请求</a></p>";
                            break;
                        case 10:
                            p = "<p id='WB_unread_msg_10'>" + json[i].count + "条新推荐，<a href='http://www.sodao.com/home/message/demand#rt=3' target='_blank'>查看推荐</a></p>";
                            break;
                        case 11:
                            p = "<p id='WB_unread_msg_11'>" + json[i].count + "条新应用邀请，<a href='http://www.sodao.com/home/message/demand#rt=4' target='_blank'>查看邀请</a></p>";
                            break;
                        case 12:
                            p = "<p id='WB_unread_msg_12'>" + json[i].count + "条新专区邀请，<a href='http://www.sodao.com/home/message/demand#rt=6' target='_blank'>查看邀请</a></p>";
                            break;
                        case 13:
                            p = "<p id='WB_unread_msg_13'>" + json[i].count + "条新私信，<a href='http://www.sodao.com/home/Message/inbox' target='_blank'>查看私信</a></p>";
                            break;
                        case 14:
                            p = "<p id='WB_unread_msg_14'>" + json[i].count + "条新赞，<a href='http://www.sodao.com/home/Message/notice' target='_blank'>查看赞</a></p>";
                            break;
                        case 15:
                            p = "<p id='WB_unread_msg_15'>" + json[i].count + "条秀评论，<a href='http://www.sodao.com/home/dynamic/commentmsglist' target='_blank'>查看秀评论</a></p>";
                            break;
                        case 16:
                            p = "<p id='WB_unread_msg_16'><a href='http://www.sodao.com/home/profile/weibosetting' target='_blank'>微博消息同步</a></p>";
                            break;
                        case 17:
                            p = "<p id='WB_unread_msg_17'>" + json[i].count + "条秀回复，<a href='http://www.sodao.com/home/message/notice' target='_blank'>查看秀回复</a></p>";
                            break;
                        case 18:
                            p = "<p id='WB_unread_msg_18'>" + json[i].count + "条动态提到我，<a href='http://www.sodao.com/home/index?u=" + data.user + "&target=8&type=1' target='_blank'>查看@我</a></p>";
                            break;
                        case 19:
                            p = "<p id='WB_unread_msg_19'>" + json[i].count + "条评论提到我，<a href='http://www.sodao.com/home/dynamic/commentatme' target='_blank'>查看@我</a></p>";
                            break;
                        case 20:
                            p = "<p id='WB_unread_msg_20'>" + json[i].count + "条新通知，<a href='http://www.sodao.com/home/message/notice' target='_blank'>查看通知</a></p>";
                            break;
                    }
                    float_p = float_p + p;
                    showTip += 1;
                }
            }
            if (float_p != "" && float_p != null && float_p != "undefined") {
                $("#divNoticeTip").find(".NoticeContent").html(float_p);
                $("#divNoticeTip").show();
            }
            if (showTip > 0) {
                newMessageRemind.addTip();
            }
            else {
                newMessageRemind.delTip();
            }
        }
        else {
            $("#divNoticeTip").hide();
            newMessageRemind.delTip();
        }
    },
    NoticeClear: function () {
        var ajax = { url: "/message/noticeclear", type: "get", dataType: "json", cache: false,
            success: function (data) {
                newMessageRemind.delTip();
            }
        };
        $.ajax(ajax);
    }
};
/*
新消息提醒
*/
var newMessageRemind = {
    _step: 0,
    _title: document.title,
    _timer: null,
    show: function () {
        var temps = newMessageRemind._title.replace("【　　　】", "").replace("【新消息】", "");
        newMessageRemind._timer = setTimeout(function () {
            newMessageRemind.show();
            if (SoDao.getCookie('sodao_newMessageRemind') != '1') {
                document.title = newMessageRemind._title;
                return;
            }
            newMessageRemind._step++;
            if (newMessageRemind._step == 3) { newMessageRemind._step = 1 };
            if (newMessageRemind._step == 1) { document.title = '【　　　】' + temps };
            if (newMessageRemind._step == 2) { document.title = '【新消息】' + temps };
        }, 1500);

        return [newMessageRemind._timer, newMessageRemind._title];
    },
    clear: function (_timerArr) {
        if (_timerArr) {
            try {
                clearTimeout(_timerArr[0]);
                document.title = _timerArr[1];
            }
            catch (e) { }
        };
    },
    addTip: function () {
        SoDao.setCookie('sodao_newMessageRemind', '1', 100);
    },
    delTip: function () {
        SoDao.setCookie('sodao_newMessageRemind', '0', -1);
    }
};
